﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZenInterface
{
    public partial class spectralGraphClass : Form
    {

        Properties.Settings settings;

        public spectralGraphClass(Properties.Settings inSettings)
        {
            InitializeComponent();
            settings = inSettings;

            chart.ChartAreas[0].AxisX.Maximum = settings.applicationDataBufferSize;

            int i = chart.Series[0].Points.Count;

            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[0].Points.AddXY(i, 0);
            }
            i = chart.Series[1].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[1].Points.AddXY(i, 0);
            }
            i = chart.Series[2].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[2].Points.AddXY(i, 0);
            }
            i = chart.Series[3].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[3].Points.AddXY(i, 0);
            }
            i = chart.Series[4].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[4].Points.AddXY(i, 0);
            }
            i = chart.Series[5].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[5].Points.AddXY(i, 0);
            }
            i = chart.Series[6].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[6].Points.AddXY(i, 0);
            }
            i = chart.Series[7].Points.Count;
            for (; i < settings.applicationDataBufferSize; i++)
            {
                chart.Series[7].Points.AddXY(i, 0);
            }

            for (int j = 0; j < chart.ChartAreas.Count; j++)
            {
                chart.ChartAreas[j].AxisX.Maximum = settings.applicationDataBufferSize;
            }
        }
        public void update(DatabaseZenDataSet inDataSet)
        {

            DataTable dataTable = inDataSet.DataTableDigitalFilter0;
            DataRow dataRow;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                dataRow = dataTable.Rows[i];
                chart.Series[0].Points[i].SetValueXY(i, dataRow[5]);
                //chart.Series[4].Points[i].SetValueXY(i, dataRow[6]);

            }

            dataTable = inDataSet.DataTableDigitalFilter1;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                dataRow = dataTable.Rows[i];
                chart.Series[1].Points[i].SetValueXY(i, dataRow[5]);
                //chart.Series[5].Points[i].SetValueXY(i, dataRow[6]);
            }

            dataTable = inDataSet.DataTableDigitalFilter2;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                dataRow = dataTable.Rows[i];
                chart.Series[2].Points[i].SetValueXY(i, dataRow[5]);
                //chart.Series[6].Points[i].SetValueXY(i, dataRow[6]);
            }

            dataTable = inDataSet.DataTableDigitalFilter3;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                dataRow = dataTable.Rows[i];
                chart.Series[3].Points[i].SetValueXY(i, dataRow[5]);
                //chart.Series[7].Points[i].SetValueXY(i, dataRow[6]);
            }

            chart.Invalidate();
        }

        private void spectralGraphClass_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }


    }
}
